package scripts.sea;

import api.sea.DelegationApi;
import api.sea.LoginApi;
import com.alibaba.fastjson.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import util.AssertUtil;
import util.HttpClientUtils;
import util.ResponseData;
import util.TestDataUtil;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Arrays;

/**
 * 委托单列表
 */
public class TestDelegation {
    private static final Logger logger= LoggerFactory.getLogger(TestDelegation.class);
    private static final LoginApi loginApi=new LoginApi();
    @Test
    public static void test_01() throws IOException, URISyntaxException {
        ResponseData responseData= loginApi.login("admin","qf123456?");
        String data = responseData.getBody().getJSONObject("data").getString("logistics-token");
        HttpClientUtils.build_header("logistics-token",data);
        HttpClientUtils.build_header("Content-Type","application/json");
    }
    @DataProvider
    public Object[][] build_data() throws IOException {
        String key="truckCompanyCode,truckCompany,cabinetNumber,addressBook,fbaCode,cartonSizeList," +
                "shippingDate,startPort,arrivePort,tradeName,deliveryDate,transportWay,customerOrderNumber," +
                "isTax,transportNumber,transportCost,isPasteList,isPalletize,trayLength,trayWidth,trayHeight," +
                "sendPalletsNumber,totalCartons,totalGrossWeight,totalVolume,company,recipients,country,addressOne," +
                "addressTwo,zipCode,phone,mark,deliveryExplain,palletizeType,storeNumber,warehouse,containerWay," +
                "addressType,markType,salesmanName,salesmanId,operatorId,operatorName,foreignOperatorId,foreignOperatorName," +
                "customerName,customerCode,kukaiType";
                Object[][] test_data = TestDataUtil.build_data("delegation.json", key);
        logger.info("test_data={}", Arrays.deepToString(test_data));
        return test_data;
    }
    @Test(dataProvider = "build_data")
    public static void test_02(String truckCompanyCode, String truckCompany, String  cabinetNumber, int addressBook,
                                       String fbaCode, JSONArray cartonSizeList, String shippingDate,
                                       String startPort, String arrivePort, String tradeName, String deliveryDate, String transportWay,
                                       String customerOrderNumber, String isTax, String transportNumber,
                                       String transportCost, String isPasteList, String isPalletize, String trayLength, String trayWidth,
                                       String trayHeight, String sendPalletsNumber, int totalCartons,
                                       int totalGrossWeight, int totalVolume, String company, String recipients, String country,
                                       String addressOne, String addressTwo, String zipCode, String phone, String mark,
                                       String deliveryExplain, String palletizeType, String storeNumber, String warehouse,
                                       String containerWay, String  addressType, int markType, String salesmanName, String salesmanId,
                                       String operatorId, String operatorName, String foreignOperatorId, String foreignOperatorName,
                                       String customerName, String customerCode, int kukaiType) throws IOException, URISyntaxException {
        ResponseData responseData= DelegationApi.delegation(truckCompanyCode,truckCompany,cabinetNumber,addressBook,fbaCode,
                cartonSizeList,shippingDate,startPort,arrivePort,tradeName,deliveryDate,transportWay,customerOrderNumber,
                isTax,transportNumber,transportCost,isPasteList,isPalletize,trayLength,trayWidth,trayHeight,sendPalletsNumber,
                totalCartons,totalGrossWeight,totalVolume,
                company,recipients,country,addressOne,addressTwo,
                zipCode,phone,mark,deliveryExplain,palletizeType,storeNumber,warehouse,containerWay,
                addressType,markType,salesmanName,salesmanId,operatorId,operatorName,foreignOperatorId,
                foreignOperatorName,customerName,customerCode,kukaiType);
        logger.info("响应体数据={}",responseData.getBody());
        AssertUtil.assertCommon(responseData,0,"成功");
    }
}
